<?php
class Zen_View_Helper_Render_Tile extends Zend_View_Helper_Abstract {
	
	private $_per_line = 3;
	private $_item_css = '';
	
	public function render_Tile($items, $render_script, $params=array() ) {
		if (! $items) return '';
		$html = '';
		$per_line = ( isset($params['per_line']) ) ? $params['per_line'] : $this->_per_line;
		$item_css = ( isset($params['item_css']) ) ? $params['item_css'] : $this->_item_css;   
		$groups = array_chunk($items, $per_line);
		$view = $this->view;
		foreach ($groups as $group){
			$html .= '<div class="line clearfix">';
			$group = Zen_Filter_EdgeArray::filter($group);
			foreach ($group as $item) {
				$first 	= ( isset($item['first']) ) ? 'first' : '';
				$last 	= ( isset($item['last']) )  ? 'last' : '';
				$html  .= "<div class='item-wrapper block-left $first $last $item_css'>";
				ob_start ();
				require $render_script;
				$html  .= ob_get_contents();
				ob_end_clean ();
				$html  .= '</div>';
			}
			$html .= '</div>';
		}
		return $html;
	}
	
	
}